﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleHardwareMonitor
{

    public class AllStateValue
    {
        //物理网卡地址
        private string _mac = "";
        public string mac
        {
            get
            {
                return _mac;
            }
            set
            {
                _mac = value;
            }
        }
        //网络类型
        private NetType _netType = NetType.NET;
        public NetType netType
        {
            get
            {
                return _netType;
            }
            set
            {
                _netType = value;
            }
        }
        //网络连接状态
        private LinkState _linkState = LinkState.OK;
        public LinkState linkState
        {
            get
            {
                return _linkState;
            }
            set
            {
                _linkState = value;
            }
        }
        //网络信号强度
        private string _wsig = "";
        public string wsig
        {
            get
            {
                return _wsig;
            }
            set
            {
                _wsig = value;
            }
        }
        //网络速率
        private string _wSpeed = "";
        public string wSpeed
        {
            get
            {
                return _wSpeed;
            }
            set
            {
                _wSpeed = value;
            }
        }
        //CPU 温度
        private CpuTemperature _cpuTemperature = null;
        public CpuTemperature cpuTemperature
        {
            get
            {
                if (_cpuTemperature == null)
                {
                    _cpuTemperature = new CpuTemperature();
                }
                return _cpuTemperature;
            }
            set
            {
                _cpuTemperature = value;
            }
        } 
        //GPU 温度
        private GpuTemperature _gpuTemperature = null;
        public GpuTemperature gpuTemperature
        {
            get
            {
                if (_gpuTemperature == null)
                {
                    _gpuTemperature = new GpuTemperature();
                }
                return _gpuTemperature;
            }
            set
            {
                _gpuTemperature = value;
            }
        }
        //主板温度
        private MainboardTemperature _mainboardTemperature = null;
        public MainboardTemperature mainboardTemperature
        {
            get
            {
                if (_mainboardTemperature == null)
                {
                    _mainboardTemperature = new MainboardTemperature();
                }
                return _mainboardTemperature;
            }
            set
            {
                _mainboardTemperature = value;
            }
        }
        //硬盘温度
        private HDDTemperature _hddTemperature = null;
        public HDDTemperature hddTemperature
        {
            get
            {
                if (_hddTemperature == null)
                {
                    _hddTemperature = new HDDTemperature();
                }
                return _hddTemperature;
            }
            set
            {
                _hddTemperature = value;
            }
        }
        //CPU 负载率
        private CPULoad _cpuLoad = null;
        public CPULoad cpuLoad
        {
            get
            {
                if (_cpuLoad == null)
                {
                    _cpuLoad = new CPULoad();
                }
                return _cpuLoad;
            }
            set
            {
                _cpuLoad = value;
            }
        }
        //硬盘使用率
        private HDDLoad _hddLoad = null;
        public HDDLoad hddLoad
        {
            get
            {
                if (_hddLoad == null)
                {
                    _hddLoad = new HDDLoad();
                }
                return _hddLoad;
            }
            set
            {
                _hddLoad = value;
            }
        }
        //系统总音量
        private float _volume = 0;
        public float volume
        {
            get
            {
                return _volume;
            }
            set
            {
                _volume = value;
            }
        }
    }

    public class HeartbeatValue
    {
        //物理网卡地址
        private string _mac = "";
        public string mac {
            get
            {
                return _mac;
            }
            set
            {
                _mac = value;
            }
        }
        //网络类型
        private NetType _netType = NetType.NET;
        public NetType netType
        {
            get
            {
                return _netType;
            }
            set
            {
                _netType = value;
            }
        }
        //网络连接状态
        private LinkState _linkState = LinkState.OK;
        public LinkState linkState
        {
            get
            {
                return _linkState;
            }
            set
            {
                _linkState = value;
            }
        }
        //网络信号强度
        private string _wsig = "";
        public string wsig
        {
            get
            {
                return _wsig;
            }
            set
            {
                _wsig = value;
            }
        }
        //网络速率
        private string _wSpeed = "";
        public string wSpeed
        {
            get
            {
                return _wSpeed;
            }
            set
            {
                _wSpeed = value;
            }
        }
        //CPU 温度
        private CpuTemperature _cpuTemperature = null;
        public CpuTemperature cpuTemperature
        {
            get
            {
                if (_cpuTemperature == null)
                {
                    _cpuTemperature = new CpuTemperature();
                }
                return _cpuTemperature;
            }
            set
            {
                _cpuTemperature = value;
            }
        }
    }
    interface IHardwareValue
    {
        float minValue { get; set; }
        float maxValue { get; set; }
        float totalValue { get; set; }
        int count { get; set; }
    }

    public class HardwareValue : IHardwareValue
    {
        
        public float minValue { get; set; }
        public float maxValue { get; set; }
        public float totalValue { get; set; }
        public int count { get; set; }

        public float aveValue
        {
            get
            {
                return (this.count <= 0) ? 0 : Convert.ToSingle(this.totalValue / this.count);
            }
        }

        public HardwareValue()
        {
            this.maxValue = 0;
            this.minValue = 9999999999;
            this.totalValue = 0;
            this.count = 0;
        }
        public void SetValue(float? value = null)
        {
            if (value == null) return;
            float tempValue = Convert.ToSingle(value);
            this.minValue = this.minValue > tempValue ? tempValue : this.minValue;
            this.maxValue = this.maxValue < tempValue ? tempValue : this.maxValue;
            this.totalValue += tempValue;
            this.count++;
        }
    }

    public class CpuTemperature : HardwareValue { }
    public class GpuTemperature : HardwareValue { }
    public class MainboardTemperature : HardwareValue { }
    public class HDDTemperature : HardwareValue { }
    public class CPULoad : HardwareValue { }
    public class HDDLoad
    {
        public List<Section> sections { get; set; }

        public HDDLoad()
        {
            this.sections = new List<Section>();
        }

        public override string ToString()
        {
            string sectionsStr = "";
            foreach (Section section in this.sections)
            {
                sectionsStr += section.name + ";" + section.value.ToString() + ",";
            }
            if (!string.IsNullOrEmpty(sectionsStr) && sectionsStr.Length > 0)
            {
                sectionsStr = sectionsStr.Substring(0, sectionsStr.Length - 1);
            }
            return sectionsStr;
        }
    }
    public class Section
    {
        public string name { get; set; }
        public float value { get; set; }

        public Section()
        {
            this.name = "";
            this.value = 0;
        }
    }
}
